<?php
$link = mysql_connect('127.0.0.1', 'user', 'pass');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully', "\n";

$db_selected = mysql_select_db('messagesdb', $link);

$id = isset($_GET['id']) ? $_GET['id'] : '1'; //some default user id.
$by = 'sid';

$count = mysql_query(sprintf("SELECT count(id) as count FROM messsage WHERE %s=%s", $by, $id));
$row = mysql_fetch_assoc($count);

$result = mysql_query(sprintf("SELECT * FROM messsage WHERE %s=%s LIMIT 20", $by, $id));
?>
<h1><?php echo "Number of messages: ", $row['count'], "\n";?></h1>
<table>
  <tr>
    <td>
      ID
    </td>
    <td>
      NICKNAME
    </td>
    <td>
      GENDER
    </td>
    <td>
      AGE
    </td>
    <td>
      SUBJECT
    </td>
  </tr>
<?php while($msg = mysql_fetch_assoc($result)): ?>
  <tr>
    <td>
      <?php echo $msg['id'] ?>
    </td>
    <td>
      <?php echo $msg['s_nickname']; ?>
    </td>
    <td>
      <?php echo $msg['s_gender']; ?>
    </td>
    <td>
      <?php echo $msg['s_age']; ?>
    </td>
    <td>
      <?php echo $msg['subject']; ?>
    </td>
  <tr>
<?php endwhile; ?>
</table>